package com.alliky.core.data.db

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.alliky.core.data.dao.CategoryDao
import com.alliky.core.data.dao.GoodsDao
import com.alliky.core.data.dao.RemoteKeyDao
import com.rrc.common.entity.CategoryVO
import com.rrc.common.entity.GoodsVO
import com.rrc.common.entity.RemoteKey
import com.alliky.core.utils.RxUtils
import java.security.AccessControlContext

/**
 * ================================================
 * @Description: 描述
 * @Author: wxianing
 * @Date: 2022/11/24 16:45
 * ================================================
 */

@Database(
    entities = [
        GoodsVO::class,
        CategoryVO::class,
        RemoteKey::class,
    ],
    version = 1,
    exportSchema = false
)
abstract class AppDatabase : RoomDatabase() {

    abstract fun goodsDao(): GoodsDao
    abstract fun categoryDao(): CategoryDao
    abstract fun remoteKeyDao(): RemoteKeyDao

    companion object {
        private const val DB_NAME = "database.db"

        @Volatile
        private var instance: AppDatabase? = null

        fun get(context: Context): AppDatabase {
            return instance ?: Room.databaseBuilder(
                context, AppDatabase::class.java,
                DB_NAME
            ).build().also {
                instance = it
            }
        }
    }
}